package com.qingyun.system.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qingyun.system.common.util.StringUtil;
import com.qingyun.system.model.entity.Message;
import com.qingyun.system.model.query.MessageQuery;
import com.qingyun.system.model.vo.MessageVO;
import com.qingyun.system.model.vo.PageVO;
import com.qingyun.system.service.MessageService;
import com.qingyun.system.mapper.MessageMapper;
import org.springframework.stereotype.Service;

/**
* @author khb78
* @description 针对表【biz_message(访客与客服的聊天记录信息表)】的数据库操作Service实现
* @createDate 2024-12-16 17:06:03
*/
@Service
public class MessageServiceImpl extends ServiceImpl<MessageMapper, Message>
    implements MessageService{

    /**
     * 根据条件分页查询聊天记录
     * @param messageQuery 查询条件
     * @return 查询结果对象
     */
    @Override
    public PageVO<MessageVO> queryMessageList(MessageQuery messageQuery) {
        Page<Message> page = this.lambdaQuery()
                .eq(messageQuery.getSenderId() != null,Message::getSenderId,messageQuery.getSenderId())
                .eq(messageQuery.getSenderType()!= null,Message::getSenderType,messageQuery.getSenderType())
                .eq(StringUtil.isNotBlank(messageQuery.getCreateBy()),Message::getCreateBy,messageQuery.getCreateBy())
                .like(StringUtil.isNotBlank(messageQuery.getMessage()), Message::getMessage,messageQuery.getMessage())
                .between(messageQuery.getStartTime() != null && messageQuery.getEndTime() != null,
                        Message::getSentTime,messageQuery.getStartTime(),messageQuery.getEndTime())
                .page(messageQuery.toMpPage("create_time", false));

        return PageVO.of(page, MessageVO.class);
    }
}




